/*
 * Attemp to solve the treasure hunt problem.
 */
#include "stdafx.h"
using namespace std;

void treasure_hunt_main()  {
	int n_machines, n_tokens, start_machine, n_turns;
	cin >> n_machines >> n_tokens >> start_machine >> n_turns;

	// allocate a big array to store the state machine information
	int total_states = n_machines*n_tokens;
	
	vector<int> next_state(total_states);
	// track the turn on which this state was visited
	vector<int> turn_count (total_states);

	// input the states
	for(int i = 0; i < total_states; i++)  {
		int token, machine;
		cin >> token >> machine;
		
		next_state[i] = (machine-1)*n_tokens + (token-1);
		turn_count[i] = 0;
	}

	int state = (start_machine-1)*n_tokens;
	int this_turn = 1;
	int turns_remaining = 1;
	int dec_turns = 0;

	for(;this_turn != n_turns && turns_remaining; this_turn++)  {
		if(turn_count[state])  {
			int loop_len = this_turn - turn_count[state];
			turns_remaining = (n_turns - this_turn) % loop_len;
			dec_turns = 1;
		}
		turn_count[state] = this_turn;
		state = next_state[state];
		if(dec_turns)
			turns_remaining--;
	}
	cout << (state / n_tokens)+1;
}